package cn.xiuxian.service.impl;

import cn.xiuxian.dao.IUserDao2;
import cn.xiuxian.dao.IVideoDao2;
import cn.xiuxian.dao.impl.UserDaoImpl3;
import cn.xiuxian.dao.impl.VideoDaoImpl2;
import cn.xiuxian.model.dto.UserDTO;
import cn.xiuxian.model.pojo.User;
import cn.xiuxian.model.pojo.Video;
import cn.xiuxian.service.IUserService;

import java.util.ArrayList;
import java.util.List;

public class UserServiceImpl implements IUserService {

    private IUserDao2 userDao2 = new UserDaoImpl3();

    private IVideoDao2 videoDao2 = new VideoDaoImpl2();

    @Override
    public List<UserDTO> findAll() {
        List<User> userList = userDao2.findAllUser();

        List<UserDTO>  userDTOList = new ArrayList<>();

        userList.forEach(u ->{
            List<Video>  videoList = videoDao2.findAllVideoByUserid(u.getId());

            UserDTO  userDTO = new UserDTO();
            userDTO.setUser(u);
            userDTO.setVideoList(videoList);
            userDTOList.add(userDTO);

        });
        return userDTOList;
    }
}
